How to : refactor code with encapsulate field 如何:用封裝字段重構(gòu)代碼
The code that is generated by this refactoring operation is modeled by the encapsulate field code snippets 此重構(gòu)操作生成的代碼將由“封裝字段代碼段”來建模。
To create the new property , the encapsulate field operation changes the access modifier for the field that you want to encapsulate to 為了創(chuàng)建新屬性, “封裝字段”操作將為要封裝為
For example , if you highlight code that is not a field declaration , you can not select the encapsulate field option 例如,如果突出顯示的代碼不是字段聲明,則無法選擇“封裝字段”選項(xiàng)。
The encapsulate field operation is only possible when the cursor is positioned on the same line as the field declaration 僅當(dāng)將光標(biāo)與字段聲明置于同一行時,才可以執(zhí)行“封裝字段”操作。
Available refactoring options include rename , extract method , extract interface , change signature , and encapsulate field 可用的重構(gòu)選項(xiàng)包括重命名、提取方法、提取接口、更改簽名和封裝字段。
Other refactoring options include encapsulating fields , promoting local variables to method parameters , and managing method parameters 其他重構(gòu)選項(xiàng)包括封裝字段、將局部變量提升為方法參數(shù)以及管理方法參數(shù)。
Supports more than 15 individual refactoring features , including operations like reorder parameters , extract method , encapsulate field , and create overload 支持超過15種單獨(dú)的重構(gòu)功能,包括重新排列參數(shù)、提取方法、封裝字段及創(chuàng)建重載等操作。
Encapsulate field refactoring operation enables you to quickly create a property from an existing field , and then seamlessly update your code with references to the new property 利用“封裝字段”重構(gòu)操作,可以從現(xiàn)有字段快速創(chuàng)建屬性,然后使用對新屬性的引用無縫更新代碼。
For declarations that declare multiple fields , encapsulate field uses the comma as a boundary between fields , and initiates refactoring on the field that is nearest the cursor , on the same line as the cursor 對于聲明多個字段的聲明, “封裝字段”使用逗號作為字段之間的邊界,并對與光標(biāo)位于同一行且距離光標(biāo)最近的某個字段啟動重構(gòu)。